<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ page import="com.scalar.chiptrack.utils.ConfigManager" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/wipInventoryReport.do?action=releaseLots"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); /*try {*/ %>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>
</HEAD>
<script language="javascript">

    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }

    function validateFromAndToDates()
    {
        formdoc = document.wipInventoryReportForm;
        errMsg = '';

        var pa	= document.getElementById("message")

        if(chkDate(formdoc.fromDate.value,'From-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.fromDate.focus();
            return false;
        }

        if(chkDate(formdoc.toDate.value,'To-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.toDate.focus();
            return false;
        }

        if(formdoc.fromDate.value!='' && formdoc.toDate.value!='')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.fromDate.value),formatDateAsMMDDYYYY(formdoc.toDate.value)))
            {
                pa.innerHTML = "To Date cannot be less than From Date";
                formdoc.toDate.focus();
                return false;
            }
        }
        return true;
    }

    function loadProductsbyType()
    {
	    document.wipInventoryReportForm.action="<%=chipTracContext%>/wipInventoryReport.do?action=releaseLots&psType="+document.wipInventoryReportForm.psType.value;
	    document.wipInventoryReportForm.submit();
    }

    function submitReport(fileType)
    {
        var d = new Date();
        var day = d.getDate();
        var month = d.getMonth()+1;
        var year = d.getFullYear();
        var hour = d.getHours();
        var min = d.getMinutes();
        var sec = d.getSeconds();
        var pa	= document.getElementById("message");
        var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;
        var success;
        var formdoc = document.wipInventoryReportForm;

        var reportType = "";
        var psType = "";
        psType = formdoc.psType.value;

        for ( var i = 0; i < formdoc.reportType.length; i++ )
        {
            if ( formdoc.reportType[i].checked )
            {
                reportType = formdoc.reportType[i].value;
                //alert("reportType"+reportType);
            }
        }

        success = true;
        success = validateFromAndToDates();
        if( success == false )
        {
            //pa.innerHTML = errMsg;
            return;
        }
        pa.innerHTML = errMsg;
        if ( reportType != 'binDiscrepancy' && (psType == '0' || psType == null ) )
        {
            pa.innerHTML = "<li> Please select Process Type ";
            return ;
        }

        var partNumberObj = formdoc.productId;
        var processstepId = "";
        var count = 0;
        for( var i = 0; i < partNumberObj.length; i++ )
        {
            if( partNumberObj.options[i].selected )
            {
                count++;
                if ( processstepId != '' )
                {
                    processstepId = processstepId + "," + partNumberObj.options[i].value;
                }
                else
                {
                    processstepId = partNumberObj.options[i].value;
                    if( partNumberObj.options[i].value == '0' )
                    {
                        break;
                    }
                }
            }
        }
        if ( processstepId == '')
        {
            processstepId = "0";
        }
        if( count > 10)
        {
            pa.innerHTML = "<li>Please select upto 10 Products only";
            return;
        }
        else
        {
            formdoc.prompt0.value = processstepId;
        }


        if ( formdoc.vendorId.value == '' )
        {
            formdoc.prompt1.value = '0';
        }
        else
        {
            formdoc.prompt1.value = formdoc.vendorId.value;
        }

        if ( formdoc.lotStatus.value == '' )
        {
            formdoc.prompt2.value = '0';
        }
        else
        {
            formdoc.prompt2.value = formdoc.lotStatus.value;
        }

        if ( formdoc.lotCategory.value == '' )
        {
            formdoc.prompt3.value = '0';
        }
        else
        {
            formdoc.prompt3.value = formdoc.lotCategory.value;
        }

        if ( formdoc.fromDate.value == '' )
        {
            formdoc.prompt4.value = '0';
        }
        else
        {
            formdoc.prompt4.value = formdoc.fromDate.value;
        }

        if ( formdoc.toDate.value == '' )
        {
            formdoc.prompt5.value = '0';
        }
        else
        {
            formdoc.prompt5.value = formdoc.toDate.value;
        }

        formdoc.prompt6.value = reportType;
        formdoc.prompt8.value = defaultPrompt;;
        formdoc.prompt9.value = psType;
        formdoc.prompt10.value = '';

        if ( reportType == 'binDiscrepancy' )
        {
            fileType = 3;
        }

        if( fileType == 2 )
        {
            formdoc.prompt7.value = "Xlreport";

            var url = '<%=chipTracContext%>/dataDumpReportAction.do?action=generateReleaseReportXls&popUp=true&prompt0=' + formdoc.prompt0.value + '&prompt1=' + formdoc.prompt1.value + '&prompt2=' + formdoc.prompt2.value + '&prompt3=' + formdoc.prompt3.value + '&prompt4=' + formdoc.prompt4.value+ '&prompt5=' + formdoc.prompt5.value+ '&prompt6=' + formdoc.prompt6.value+ '&prompt7=' + formdoc.prompt7.value+ '&prompt8=' + formdoc.prompt8.value+ '&prompt9='+formdoc.prompt9.value ;
            newWindow = window.open ( url, 'ReleaseReport', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=450,height=150,resizable=yes');
        
        }
        else if( fileType == 3 )
        {               
            formdoc.action = '<%=chipTracContext%>/dataDumpReportAction.do?action=binningDiscrepanyReportXls&prompt0=' + formdoc.prompt0.value + '&prompt1=' + formdoc.prompt1.value;
            formdoc.submit();
        }
        else
        {

            if ( psType == 'Assembly')
            {
                formdoc.prompt7.value = "Crystal";
                if ( reportType == 'Detail')
                {
                    formdoc.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Operations/Assembly_Release_Report_Detail.rpt";
                }
                else
                {
                    formdoc.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Operations/Assembly_Release_Report_Summary.rpt";
                }
                formdoc.submit();
            }
            else if ( psType == 'FT')
            {
               formdoc.prompt7.value = "Xlreport";
                
               var url = '<%=chipTracContext%>/dataDumpReportAction.do?action=generateReleaseReportXls&popUp=true&prompt0=' + formdoc.prompt0.value + '&prompt1=' + formdoc.prompt1.value + '&prompt2=' + formdoc.prompt2.value + '&prompt3=' + formdoc.prompt3.value + '&prompt4=' + formdoc.prompt4.value+ '&prompt5=' + formdoc.prompt5.value+ '&prompt6=' + formdoc.prompt6.value+ '&prompt7=' + formdoc.prompt7.value+ '&prompt8=' + formdoc.prompt8.value+ '&prompt9='+formdoc.prompt9.value ;
                newWindow = window.open ( url, 'ReleaseReport', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=450,height=150,resizable=yes');
            }
        }
    }

    function disableFields()
    {
        var form = document.wipInventoryReportForm;

        form.psType.disabled= true;
        form.lotStatus.disabled = true;
        form.lotCategory.disabled = true;
        form.fromDate.disabled = true;
        form.toDate.disabled = true;

        form.action="<%=chipTracContext%>/wipInventoryReport.do?action=releaseLots&psType=Die Bank";
	    form.submit();
    }
    function disable()
    {
        var form = document.wipInventoryReportForm;
        var reportType = '';
        for ( var i = 0; i < form.reportType.length; i++ )
        {
            if ( form.reportType[i].checked )
            {
                reportType = form.reportType[i].value;
                //alert("reportType"+reportType);
            }
        }
        if ( reportType == 'binDiscrepancy' )
        {
            form.psType.disabled= true;
            form.lotStatus.disabled = true;
            form.lotCategory.disabled = true;
            form.fromDate.disabled = true;
            form.toDate.disabled = true;
        }
    }
    
    function enableFields()
    {
        var form = document.wipInventoryReportForm;
        var reportType = '';
        for ( var i = 0; i < form.reportType.length; i++ )
        {
            if ( form.reportType[i].checked )
            {
                reportType = form.reportType[i].value;
                //alert("reportType"+reportType);
            }
        }

        if ( reportType == 'Detail' || reportType == 'Summary')
        {
            form.action="<%=chipTracContext%>/wipInventoryReport.do?action=releaseLots&psType=0";
	        form.submit();
        }
        form.psType.disabled= false;
        form.lotStatus.disabled = false;
        form.lotCategory.disabled = false;
        form.fromDate.disabled = false;
        form.toDate.disabled = false;
    }

</script>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="disable()">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->
<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
    <!-- Side Navigation start -->
    <%@ include file="/jsp/operations/reports_side_menu.jsp" %>
    <!-- end of the side navigations -->
    </TD>
    <TD bgcolor="#ffffff">
        <IMG height="9" src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="2"></TD>
        <TD valign="top" width="100%">
        <IMG height="1" src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width="500" border="0">
        <BR>
        <html:form name="wipInventoryReportForm" type="com.scalar.chiptrack.operations.reports.forms.WipInventoryReportForm" action="/wipInventoryReport">
        <TABLE border="0" width="85%" align="center">
            <TR><TD colspan="6" class="NArialW" align="center">Release Lot Report</TD></TR>
            <TR>
                <TD colspan="6">
                    <input type="hidden" name="prompt0">
                    <input type="hidden" name="prompt1">
                    <input type="hidden" name="prompt2">
                    <input type="hidden" name="prompt3">
                    <input type="hidden" name="prompt4">
                    <input type="hidden" name="prompt5">
                    <input type="hidden" name="prompt6">
                    <input type="hidden" name="prompt7">
                    <input type="hidden" name="prompt8">
                    <input type="hidden" name="prompt9">
                    <input type="hidden" name="prompt10">
                </TD>
            </TR>
            <%--<TR><TD colspan="6">&nbsp;</TD></TR>--%>
            <TR><TD width="12%" >&nbsp;</TD><TD colspan="6" class='NArialL' align="left"><strong><FONT id="message" styleClass="NArialL" color='FF0000'>&nbsp;</FONT></strong></TD></TR>
            <TR>
                <TD>&nbsp;</TD>
                <TD colspan="6" align="left">
                  <chiptrack:info styleClass="NArialL" />
                  <chiptrack:errors styleClass="NArialL" />
                  <chiptrack:messages type="info" styleClass="NArialL" />&nbsp;
                </TD>
            </TR>
            <TR>
                <TD colspan="6">
                    <TABLE align="center" border="0" width="100%" cellspacing="3" cellpadding="2">
                        <TR>
                            <TD width="10%" >&nbsp;</TD>
                            <TD width="15%" class="NArialL" align="left" valign = 'top'>Process Type :</TD>
                            <TD width="20%" class="NArialL" valign = 'top'>
                                <html:select property="psType" name="wipInventoryReportForm" styleClass="txfield" style="width:150px" onchange = 'loadProductsbyType()'>
                                    <html:options collection="processList" property="value" labelProperty="label"/>
                                </html:select>
                            </TD>
                            <TD width="5%">&nbsp;</TD>
                            <TD width="15%" class="NArialL" valign = 'top' align = "left">Products : </TD>
                            <TD width="20%" class="NArialL" valign = 'top'>
                                <html:select property="productId" name="wipInventoryReportForm" styleClass="txfield" style="width:150px" multiple="true" size="5">
                                    <html:option value="0">All Products</html:option>
                                    <html:options collection="mktgPartNumberSelectList" property="value" labelProperty="label"/>
                                </html:select>
                            </TD>
                        </TR>
	    				  <TR><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height="1"></TD></TR>
                        <TR>
                            <TD width="10%">&nbsp;</TD>
                            <TD width="15%" class="NArialL" valign="top">Vendor :</TD>
                            <TD width="20%" class="NArialL">
                                <html:select property="vendorId" name="wipInventoryReportForm" styleClass="txfield" style="width:150px" >
                                    <html:option value="0">All Vendors</html:option>
                                    <html:options collection="toLocationList" property="value" labelProperty="label"/>
                                </html:select>
                            </TD>
                            <TD width="5%">&nbsp;</TD>
                            <TD width="15%" class="NArialL" valign="top" align = "left"> Status :</TD>
                            <TD width="20%" class="NArialL" valign="top">
                                <html:select property="lotStatus" name="wipInventoryReportForm" styleClass="txfield" style="width:150px" >
                                    <html:option value="0">All Status</html:option>
                                    <html:options collection="statusList" property="value" labelProperty="label"/>
                                </html:select>
                            </TD>
                        </TR>
                        <TR><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height="1"></TD></TR>
                        <TR>
                            <TD width="10%">&nbsp;</TD>
                            <TD width="15%" class=NArialL align = "left"> Lot Category :</TD>
                            <TD width="20%" class=NArialL >
                                <html:select property="lotCategory" name="wipInventoryReportForm" styleClass="txfield" style="width:150px" >
                                    <html:options collection="categoryList" property="value" labelProperty="label"/>
                                </html:select></TD>
                            <TD width="5%">&nbsp;</TD>                                
                            <TD width="15%" class="NArialL" valign="top" align = "left" colspan="2">
                               <html:radio name="wipInventoryReportForm" property="reportType" value="Detail" onclick="enableFields()" >By Detail </html:radio>
                               <html:radio name="wipInventoryReportForm" property="reportType" value="Summary" onclick="enableFields()" >By Summary </html:radio><br><br><br>
                               <html:radio name="wipInventoryReportForm" property="reportType" value="binDiscrepancy" onclick="disableFields()" >Binning Discrepancy</html:radio>
                            </TD>
                        </TR>
                        <TR><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height="1"></TD></TR>
                        <TR>
                            <TD width="10%">&nbsp;</TD>
                            <TD width="15%" class="NArialL" valign="top">From Date :</TD>
                            <TD width="20%" class="NArialL">
                                <html:text property="fromDate" name="wipInventoryReportForm" styleClass="txfield" size="12"/>
                                <a href="javascript:openCalendar(document.wipInventoryReportForm.fromDate)">
                                <img onMouseOver="window.status='Click here to select From date';return true" onMouseOut="window.status='';return true" border="0" align='center' title="Click here to Select From Date"
                                src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
                            </TD>
                            <TD width="5%" class="NArialL" >&nbsp;</TD>
                            <TD width="15%" class="NArialL" valign="top" align="left"> To Date : </TD>
                            <TD width="20%" class="NArialL">
                                <html:text property="toDate" name="wipInventoryReportForm" styleClass="txfield" size="12"/>
                                <a href="javascript:openCalendar(document.wipInventoryReportForm.toDate)">
                                <img onMouseOver="window.status='Click here to select To date';return true" onMouseOut="window.status='';return true" border="0" align='center' title="Click here to Select To Date"
                                src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
                            </TD>
                        </TR>
                        <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
                        <TR>
                            <TD colspan="5">&nbsp;</TD>
                            <TD colspan= "1" align="left" valign="top">
                            <a class="NArialL" href="javascript:submitReport(2)" onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
                            </TD>
                        </TR>
                        <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></TD></TR>
                        <TR>
                            <TD colspan="6" align=center>
                                <a href="javascript:submitReport(1);"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Release Report';return true" onmouseout="window.status='';return true" title='Click to Generate Release Report'></a>
                                &nbsp;&nbsp;
                                <a href="javascript:document.wipInventoryReportForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to reset search';return true" onmouseout="window.status='';return true" title="Click here to reset search"></a>
                            </TD>
                        </TR>
                        <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></TD></TR>
                    </TABLE>
                </TD>
            </TR>
        </TABLE>
        </html:form>
    </TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>
<%--<% } catch(Exception e){e.printStackTrace();} %>--%>
